package com.yu.mall.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent> {

    private Logger LOGGER =  LoggerFactory.getLogger(ApplicationStartup.class);

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        ApplicationContext ac = event.getApplicationContext();
        initMemberCache(ac);
    }

    private void initMemberCache(ApplicationContext ac) {
//        ConfigInfoMapper configInfoMapper = ac.getBean(ConfigInfoMapper.class);
//        ConfigInfo configInfo = new ConfigInfo();
//        configInfo.setConfigType("MEMBERCACHE_SERVER");
//        List<ConfigInfo> configList = configInfoMapper.selectByExample(configInfo);
//        List<String> servers= new ArrayList<String>();
//        for (int i = 0; i < configList.size(); i++) {
//            ConfigInfo info = configList.get(i);
//            servers.add(info.getConfigValue());
//        }
//        MemberCacheUtils.init((String[]) servers.toArray());
//        LOGGER.info("初始化MemberCache成功");
    }


}